﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
//using System.Windows.Forms;
//using ESRI.ArcGIS.RuntimeManager;

//namespace MyGIS.Forms
//{
//    static class Program
//    {
//        /// <summary>
//        /// 应用程序的主入口点。
//        /// </summary>
//        [STAThread]
//        static void Main()
//        {
//            try
//            {
//                // 初始化ArcGIS许可证
//                // RuntimeManager.Bind(ProductCode.EngineOrDesktop);
//                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
//                AoInitialize aoi = new AoInitialize();
//                aoi.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
//                Console.WriteLine("ArcGIS license initialized successfully.");
//            }
//            catch (Exception ex)
//            {
//                MessageBox.Show($"Failed to initialize ArcGIS license: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//                return; // 退出应用程序
//            }
//            Application.EnableVisualStyles();
//            Application.SetCompatibleTextRenderingDefault(false);
//            Application.Run(new Form1());
//        }

//    }
//}
using System;
using System.Windows.Forms;
using static ESRI.ArcGIS.RuntimeManager;
using ESRI.ArcGIS.esriSystem; // 添加此命名空间

namespace MyGIS.Forms
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            try
            {
                // 初始化 ArcGIS Runtime
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

                // 初始化 ArcObjects 许可证
                AoInitialize aoi = new AoInitialize();
                esriLicenseStatus licenseStatus = aoi.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

                if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
                {
                    MessageBox.Show("ArcGIS license checkout failed.");
                    return;
                }

                // 启动主窗体
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());

               
                aoi.Shutdown();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to initialize ArcGIS license: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
